package cn.boy.web.controller;

import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import cn.boy.domain.Adminstrator;
import cn.boy.domain.Student;
import cn.boy.service.AdminstratorService;
import cn.boy.service.AdminstratorServiceFactory;
import cn.boy.service.StudentService;
import cn.boy.service.StudentServiceFactory;
import cn.boy.utils.Util;

import com.sun.org.apache.commons.beanutils.BeanUtils;

public class StudentRegisterServlet extends HttpServlet {

	
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		//把客户端传来的参数以Map的形式接受，方便转换成JavaBean
		Map map =request.getParameterMap();
		
		/*// 要插入的对象
		String role = new String(request.getParameter("role").getBytes("ISO-8859-1"),"UTF-8");
*/		
		try {
					Student student = new Student();
					if (!Util.isEmpty(map)) {//数据用前要验证
						//使用BeanUtils工具把一个Map对象转换成一个JavaBean
						BeanUtils.populate(student, map);
						System.out.println("student --->>" + student);
						StudentServiceFactory instance = StudentServiceFactory.getInstance();
						StudentService service = instance.getStudentService();
						service.register(student);
					}
				
		} catch (Exception e) {
			e.printStackTrace();
			throw new RuntimeException(e);
			
		}
		
		
		
	}

	
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		doGet(request, response);
	}

}
